{itemplate 'public/header'}
<div class="page home search" id="page-app-store-search">
	<header class="bar bar-nav">
		<a class="pull-left back" href="javascript:;"><i class="icon icon-arrow-left"></i></a>
		<a class="pull-right" href="{php echo imurl('wmall/home/hunt');}">
			<i class="icon icon-search"></i>
		</a>
		<h1 class="title">
			{if !empty($categorys[$_GPC['cid']]['title'])}{$categorys[$_GPC['cid']]['title']}{else}全部车主{/if}
		</h1>
	</header>
	{php get_mall_menu();}
	<div class="content lazyload-container">
		<div class="hide bind-data" data-lat="{$lat}" data-lng="{$lng}" data-cid="{$_GPC['cid']}" data-dis="{$_GPC['dis']}" data-order="{$_GPC['order']}">dd</div>
		<div class="buttons-tab select-tab">
			<a href="javascript:;" class="button">{if !empty($categorys[$_GPC['cid']]['title'])}{$categorys[$_GPC['cid']]['title']}{else}车主分类{/if} <span class="icon"></span></a>
			<div class="drop-menu-list">
				<div class="list-block">
					<ul>
						<li><a class="list-button item-link border-1px-tb" href="{php echo imurl('wmall/home/search', array('cid' => 0, 'order' => $_GPC['order'], 'dis' => $_GPC['dis']));}">全部</a></li>
						{loop $categorys $row}
							<li>
								<a class="list-button item-link border-1px-b" href="{$row['link']}">
									{$row['title']}
									{if $_GPC['cid'] == $row['id']}<i class="icon icon-selected"></i>{/if}
								</a>
							</li>
						{/loop}
					</ul>
				</div>
			</div>
			<a href="javascript:;" class="button">{if !empty($orderbys[$_GPC['order']]['title'])}{$orderbys[$_GPC['order']]['title']}{else}智能排序{/if} <span class="icon"></span></a>
			<div class="drop-menu-list">
				<div class="list-block">
					<ul>
						<li><a class="list-button item-link border-1px-tb" href="{php echo imurl('wmall/home/search', array('order' => '', 'cid' => $_GPC['cid'], 'dis' => $_GPC['dis']));}"><span class="icon"></span>全部</a></li>
						{loop $orderbys $row}
						<li>
							<a class="list-button item-link border-1px-b"  href="{php echo imurl('wmall/home/search', array('order' => $row['key'], 'cid' => $_GPC['cid'], 'dis' => $_GPC['dis']));}">
								<span class="{$row['css']}"></span>
								{$row['title']}
								{if $_GPC['order'] == $row['key']}<i class="icon icon-selected"></i>{/if}
							</a>
						</li>
						{/loop}
					</ul>
				</div>
			</div>
			<a href="javascript:;" class="button">{if !empty($discounts[$_GPC['dis']]['title'])}{$discounts[$_GPC['dis']]['title']}{else}优惠活动{/if} <span class="icon"></span></a>
			<div class="drop-menu-list">
				<div class="list-block">
					<ul>
						<li><a class="list-button item-link border-1px-tb" href="{php echo imurl('wmall/home/search', array('dis' => '', 'cid' => $_GPC['cid'], 'order' => $_GPC['order']));}"><span class="icon"></span>全部</a></li>
						{loop $discounts $row}
						<li>
							<a class="list-button item-link border-1px-b" href="{php echo imurl('wmall/home/search', array('dis' => $row['key'], 'cid' => $_GPC['cid'], 'order' => $_GPC['order']));}">
								<span class="{$row['css']}"></span>
								{$row['title']}
								{if $_GPC['dis'] == $row['key']}<i class="icon icon-selected"></i>{/if}
							</a>
						</li>
						{/loop}
					</ul>
				</div>
			</div>
		</div>
		{if $carousel['slide_status'] == 1 && !empty($carousel['slide'])}
			<div class="swiper-container slide border-1px-t" data-space-between='20' data-pagination='.swiper-pagination' data-autoplay="2000">
				<div class="swiper-wrapper">
					{loop $carousel['slide'] $slide}
						<div class="swiper-slide" data-link="{$slide['link']}">
							<img src="{php echo tomedia($slide['thumb']);}" alt="">
						</div>
					{/loop}
				</div>
				<div class="swiper-pagination"></div>
			</div>
		{/if}
		{if $carousel['nav_status'] == 1 && !empty($carousel['nav'])}
			<div class="search-discount border-1px-tb">
				{loop $carousel['nav'] $nav}
					{php $i++;}
					<div class="discount-item pull-left {if $i == 1}border-1px-r{/if}" data-link="{$nav['link']}">
						<div class="discount-item-info pull-left">
							<p class="store-title">{$nav['title']}</p>
							<p class="store-subtitle">{$nav['sub_title']}</p>
						</div>
						<div class="discount-item-image pull-left">
							<img src="{php echo tomedia($nav['thumb']);}" alt="">
						</div>
						<div class="clearfix"></div>
					</div>
				{/loop}
				<div class="clearfix"></div>
			</div>
		{/if}
		<div class="store-list store-empty" id="store-list">
			<div class="common-no-con">
				<img src= "{WE7_WMALL_TPL_URL}static/img/store_no_con.png" alt="" />
				<p>努力加载中...</p>
			</div>
		</div>
		{itemplate 'public/copyright'}
	</div>
	<div class="footmark-warpper">
		<a href="javascript:;" id="go-top" class="icon icon-up"></a>
		<a href="{php echo imurl('wmall/home/footmark')}" class="footmark"><i class="icon icon-footprint"></i></a>
	</div>
	{php get_mall_danmu();}
</div>
{itemplate 'home/tpl-store'}
<script type="text/javascript" src="//webapi.amap.com/maps?v=1.3&key=550a3bf0cb6d96c3b43d330fb7d86950"></script>
<script>
$(function(){
	$(document).on('click', '.swiper-slide, .discount-item', function(){
		var url = $(this).data('link');
		location.href = url;
		return;
	});
	$(document).on("pageInit", "#page-app-store-search", function(e, id, page) {
		var $this = $(page).find('.bind-data');
		var params = {
			lat: $this.data('lat'),
			lng: $this.data('lng'),
			dis: $this.data('dis'),
			cid: $this.data('cid'),
			order: $this.data('order')
		}
		if(!params.lat || !params.lng) {
			var map, geolocation;
			map = new AMap.Map('allmap');
			map.plugin('AMap.Geolocation', function() {
				geolocation = new AMap.Geolocation({
					enableHighAccuracy: true //是否使用高精度定位，默认:true
				});
				geolocation.getCurrentPosition();
				AMap.event.addListener(geolocation, 'complete', getStoreList);//返回定位信息
				AMap.event.addListener(geolocation, 'error', function(){
					require(['tiny'], function(tiny){
						if(!tiny.cookie.get('__search_getPosition')) {
							location.reload();
							tiny.cookie.set('__search_getPosition', 1, 300);
						} else {
							getStoreList();
						}
					});
				});//返回定位出错信息
			});
		} else {
			getStoreList();
		}
		function getStoreList() {
			$.post("{php echo imurl('wmall/home/search/list');}", params, function(data){
				var result = $.parseJSON(data);
				if(result.message.error != 0) {
					$.toast(result.message.message);
					return false;
				}
				if(result.message.message.length == 0) {
					$('#store-list').addClass('store-empty');
					$('#store-list .common-no-con').find('p').html('没有符合条件的商户');
					$('#store-list .common-no-con').removeClass('hide');
				} else {
					var gettpl = $('#tpl-store-list').html();
					require(['laytpl', 'jquery.lazyload'], function(laytpl){
						laytpl(gettpl).render(result.message.message, function(html){
							$('#store-list').removeClass('store-empty');
							$('#store-list .common-no-con').addClass('hide');
							$('#store-list').append(html);
							var memoryHeight = sessionStorage.getItem(pageId);
							$pageId.find('.content').scrollTop(parseInt(memoryHeight));
							$('#store-list').find("img.lazyload").lazyload({
								container: $('.lazyload-container'),
								effect : 'fadeIn',
								threshold : 200
							});
							return;
						});
					});
				}
			});
		}
	});
});
</script>
{itemplate 'public/footer'}